local skel = fk.CreateSkill {
  name = "emo__lingyin",
}

skel:addEffect("viewas", {
  pattern = ".|.|.|.|.|basic",
  prompt = function (self, player, selected_cards, selected)
    if player.hp > player:getHandcardNum() then
      return "#emo__lingyin2"
    else
      return "#emo__lingyin"
    end
  end,
  interaction = function (self, player)
    local mark = player:getTableMark("@$emo__lingyin-round")
    local all_names = Fk:getAllCardNames("b")
    local names = player:getViewAsCardNames(skel.name, all_names, nil, mark)
    if #names == 0 then return end
    return UI.CardNameBox {choices = names}
  end,
  card_filter = function (self, player, to_select, selected)
    return #selected < 2
  end,
  view_as = function (self, player, cards)
    if not self.interaction.data then return end
    if #cards == 2 or (#cards == 0 and player.hp > player:getHandcardNum()) then
      local card = Fk:cloneCard(self.interaction.data)
      card:addSubcards(cards)
      card.skillName = skel.name
      return card
    end
  end,
  before_use = function(self, player, use)
    local room = player.room
    if #use.card.subcards == 0 then
      room:loseHp(player, 1, skel.name)
    end
    room:addTableMarkIfNeed(player, "@$emo__lingyin-round", use.card.trueName)
  end,
  enabled_at_play = function(self, player)
    return true
  end,
  enabled_at_response = function (self, player, response)
    if response then return false end
    local mark = player:getTableMark("@$emo__lingyin-round")
    local all_names = Fk:getAllCardNames("b")
    return #player:getViewAsCardNames(skel.name, all_names, nil, mark) > 0
  end,
})

Fk:loadTranslationTable{
  ["emo__lingyin"] = "泠音",
  [":emo__lingyin"] = "每轮每牌名限一次，你可以将两张牌当任意基本牌使用，若你体力值大于手牌数，可改为失去一点体力视为使用之。",

  ["@$emo__lingyin-round"] = "泠音",
  ["#emo__lingyin"] = "泠音：将两张牌当任意基本牌使用",
  ["#emo__lingyin2"] = "泠音：选两张牌/失去1体力 当任意基本牌使用",
}

return skel
